<?php

/**
 * @author vladone
 * @copyright 2008
 */

class db
{
    const my_HOST = 'localhost';
    const my_USER = 'vlad';
    const my_PASS = 'lala';
    const my_DB = 'masmovil';

    private $connection;

    public function __construct()
    {
        $this->connection = @mysql_connect(self::my_HOST, self::my_USER, self::my_PASS);
        if (!$this->connection) {
            die(mysql_error());
        }
        $db_selected = @mysql_select_db(self::my_DB, $this->connection);
        if (!$db_selected) {
            die(mysql_error());
        }
    }
    public function insertData($table, $data)
    {
        foreach ($data as $key=>$value)
		{
			$fields .= $key.",";
			$values .= "'".$value."'".",";
		}
		$fields = substr($fields,0,-1);
		$values = substr($values,0,-1);
        $query = "INSERT INTO {$table} ({$fields}) values ({$values})";
		return mysql_query($query, $this->connection);
    }
    public function deleteData($id)
    {
        $query = "delete from users where id={$id}";
        return mysql_query($query, $this->connection);
    }
    public function updateData($id, $data)
    {
        $queryparts = array();
        foreach ($data as $key => $value) {
            $queryparts[] = "{$key} = '{$value}'";
        }
        $query = "UPDATE users SET " . join($queryparts, ",") . "
WHERE id='{$id}'";
        return mysql_query($query, $this->connection);
    }
}

?>